package com.xyy.jd_clund.task;


import com.xyy.jd_clund.service.PopErpTaskJdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
@Slf4j
public class SaticScheduleTask {
    @Autowired
    private PopErpTaskJdService popErpTaskJdService;
    //3.添加定时任务

    /**
     * 商品库存同步   一分钟执行一次
     */
    @Scheduled(cron = "0 0/1 * * * ? ")
    private void ProductStock() {
        popErpTaskJdService.JdStockToPop();
        log.info("商品库存任务执行时间:{} ", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 订单同步
     */
    @Scheduled(cron = "0 0/5 * * * ? ")
    public void orderPull() {
        popErpTaskJdService.PullOrderInfo();
        log.info("订单同步任务执行时间:{} ", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 客户信息上报
     */
    @Scheduled(cron = "0 0/10 * * * ? ")
    public void customerToErp() {
        popErpTaskJdService.JdCustomerToPop();
        log.info("客户信息上报任务执行时间:{} ", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 客户导入
     */
    @Scheduled(cron = "0 0/5 * * * ? ")
    //@PostConstruct
    public void customerToJd() {
        popErpTaskJdService.IpCustomerInfoToErp();
        log.info("客户导入任务执行时间:{} ", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 订单分拣
     */
    @Scheduled(cron = "0 0/3 * * * ? ")
    public void OrderComp() {
        popErpTaskJdService.OrderComplete();
        log.info("订单分拣任务执行时间:{} ", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 出库明细
     */
    @Scheduled(cron = "0 0/30 * * * ? ")
    public void orderDetail() {
        popErpTaskJdService.orderDeliver();
        log.info("出库明细任务执行时间:{} ", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 心跳检测
     */
    @Scheduled(cron = "0 0/2 * * * ? ")
    @PostConstruct
    public void HeartbeatDetection() {
        popErpTaskJdService.syncHeartBeatMonitor();
        log.info("心跳检测任务执行时间:{} ", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }
}